﻿// Decompiled with JetBrains decompiler
// Type: UnityEngine.ScriptableObject
// Assembly: UnityEngine.CoreModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
// MVID: E6AE6B5A-2752-4B07-9528-C8B77C62CE79
// Assembly location: C:\Users\windys\Unity\2021.3.39f1c1\Editor\Data\Managed\UnityEngine\UnityEngine.CoreModule.dll
// XML documentation location: C:\Users\windys\Unity\2021.3.39f1c1\Editor\Data\Managed\UnityEngine\UnityEngine.CoreModule.xml

using System;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using UnityEngine.Bindings;
using UnityEngine.Scripting;

#nullable disable
namespace UnityEngine
{
  /// <summary>
  ///   <para>A class you can derive from if you want to create objects that live independently of GameObjects.</para>
  /// </summary>
  [RequiredByNativeCode]
  [NativeClass(null)]
  [ExtensionOfNativeClass]
  [NativeHeader("Runtime/Mono/MonoBehaviour.h")]
  [StructLayout(LayoutKind.Sequential)]
  public class ScriptableObject : Object
  {
    public ScriptableObject() => ScriptableObject.CreateScriptableObject(this);

    [Obsolete("Use EditorUtility.SetDirty instead")]
    [NativeConditional("ENABLE_MONO")]
    [MethodImpl(MethodImplOptions.InternalCall)]
    public extern void SetDirty();

    /// <summary>
    ///   <para>Creates an instance of a scriptable object.</para>
    /// </summary>
    /// <param name="className">The type of the ScriptableObject to create, as the name of the type.</param>
    /// <param name="type">The type of the ScriptableObject to create, as a System.Type instance.</param>
    /// <returns>
    ///   <para>The created ScriptableObject.</para>
    /// </returns>
    public static ScriptableObject CreateInstance(string className)
    {
      return ScriptableObject.CreateScriptableObjectInstanceFromName(className);
    }

    /// <summary>
    ///   <para>Creates an instance of a scriptable object.</para>
    /// </summary>
    /// <param name="className">The type of the ScriptableObject to create, as the name of the type.</param>
    /// <param name="type">The type of the ScriptableObject to create, as a System.Type instance.</param>
    /// <returns>
    ///   <para>The created ScriptableObject.</para>
    /// </returns>
    public static ScriptableObject CreateInstance(System.Type type)
    {
      return ScriptableObject.CreateScriptableObjectInstanceFromType(type, true);
    }

    public static T CreateInstance<T>() where T : ScriptableObject
    {
      return (T) ScriptableObject.CreateInstance(typeof (T));
    }

    [EditorBrowsable(EditorBrowsableState.Never)]
    internal static ScriptableObject CreateInstance(System.Type type, Action<ScriptableObject> initialize)
    {
      ScriptableObject instance = typeof (ScriptableObject).IsAssignableFrom(type) ? ScriptableObject.CreateScriptableObjectInstanceFromType(type, false) : throw new ArgumentException("Type must inherit ScriptableObject.", nameof (type));
      try
      {
        initialize(instance);
      }
      finally
      {
        ScriptableObject.ResetAndApplyDefaultInstances((Object) instance);
      }
      return instance;
    }

    [NativeMethod(IsThreadSafe = true)]
    [MethodImpl(MethodImplOptions.InternalCall)]
    private static extern void CreateScriptableObject([Writable] ScriptableObject self);

    [FreeFunction("Scripting::CreateScriptableObject")]
    [MethodImpl(MethodImplOptions.InternalCall)]
    private static extern ScriptableObject CreateScriptableObjectInstanceFromName(string className);

    [FreeFunction("Scripting::CreateScriptableObjectWithType")]
    [MethodImpl(MethodImplOptions.InternalCall)]
    internal static extern ScriptableObject CreateScriptableObjectInstanceFromType(
      System.Type type,
      bool applyDefaultsAndReset);

    [FreeFunction("Scripting::ResetAndApplyDefaultInstances")]
    [MethodImpl(MethodImplOptions.InternalCall)]
    internal static extern void ResetAndApplyDefaultInstances([NotNull("NullExceptionObject")] Object obj);
  }
}
